package com.isnotlocus.gulimail.product.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.isnotlocus.common.utils.PageUtils;
import com.isnotlocus.common.utils.Query;

import com.isnotlocus.gulimail.product.dao.CategoryBrandRelationDao;
import com.isnotlocus.gulimail.product.entity.CategoryBrandRelationEntity;
import com.isnotlocus.gulimail.product.service.CategoryBrandRelationService;


@Service()
public class CategoryBrandRelationServiceImpl extends ServiceImpl<CategoryBrandRelationDao, CategoryBrandRelationEntity> implements CategoryBrandRelationService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<CategoryBrandRelationEntity> page = this.page(
                new Query<CategoryBrandRelationEntity>().getPage(params),
                new QueryWrapper<CategoryBrandRelationEntity>()
        );

        return new PageUtils(page);
    }

    /**
     * 每当修改品牌名字的时候，就会修改这个表中的字段
     * @param id
     * @param name
     * @return
     */
    @Override
    public boolean updateFromBranUpdate(Long id,String name) {
        CategoryBrandRelationEntity categoryBrandRelationEntity=new CategoryBrandRelationEntity();
        categoryBrandRelationEntity.setBrandId(id);
        categoryBrandRelationEntity.setBrandName(name);
        boolean b = this.update(categoryBrandRelationEntity,new UpdateWrapper<CategoryBrandRelationEntity>().eq("brand_id",id));
        return  b;
    }

    @Override
    public void updateCategoryDetails(Long id,String name) {
        baseMapper.updateDetails(id,name);
    }

}